package com.neuedu.controller;

import com.neuedu.common.ResultJson;
import com.neuedu.dto.PrescriptionList;
import com.neuedu.entity.Prescription;
import com.neuedu.service.PrescriptionService;
import com.neuedu.service.RegisterService;
import com.neuedu.vo.PrescriptionPayVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 处方表 前端控制器
 * </p>
 *
 * @author LiYang
 * @since 2024-11-19
 */
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {

    @Resource
    PrescriptionService prescriptionService;
    @Resource
    RegisterService registerService;
    /**
     * 开设处方
     */
    @PostMapping("/add1")
    ResultJson<Boolean> add1(String content) {  //传的json类型的formdata对象
        return ResultJson.success(prescriptionService.add1(content), "开设处方成功");
    }
    @PostMapping("/add2")
    ResultJson<Boolean> add2(@RequestBody PrescriptionList data) {  // 对象 { data : 数组}
        System.out.println(data);
        return ResultJson.success(prescriptionService.add2(data), "开设处方成功");
    }
    /**
     * 开方缴费时 查询已开方的药品信息
     */
    @GetMapping("/list")
    ResultJson<List<Prescription>> list (String caseNumber, String checkState) {
        return ResultJson.success(prescriptionService.list(caseNumber, checkState));
    }

    /**
     * 缴费后 修改处方信息状态
     */
    @PostMapping("/updateState")
    ResultJson<Boolean> updateState(Integer[] ids) {
        return ResultJson.success(prescriptionService.updateState(ids));
    }

    /**
     * 发药时 查询已缴费的药品信息
     */
    @GetMapping("/fayao")
    ResultJson<?> fayao(String caseNumber) {
        Map<String, Object> map = new HashMap<>();
        map.put("register", registerService.getByCaseNumber(caseNumber));
        map.put("drugList", prescriptionService.fayao(caseNumber));
        return ResultJson.success(map);
    }

    /**
     * 发药后，更新处方状态
     */
    @PostMapping("/update")
    ResultJson<Boolean> update(Integer id) {
        return ResultJson.success(prescriptionService.update(id));
    }

    /**
     * 查看已经缴费的药品
     */
    @GetMapping("/selectPayList")
    ResultJson<PrescriptionPayVo> selectPay(String caseNumber, String checkState) {
        return ResultJson.success(prescriptionService.selectPay(caseNumber, checkState));
    }

    /**
     * 药品退费：
     *      已缴费 -》 已退费
     */
    @PostMapping("/refund")
    ResultJson<Boolean> refund(Integer[] ids) {
        return ResultJson.success(prescriptionService.refund(ids));
    }


}
